var app = new Vue({
	el: '#app',
	data: {
		orderList: [],
		openId: ''
	},
	mounted: function () {
		this.$nextTick(function () {
			openId = $.cookie('openId');
			app.openId = app.openId?app.openId:"123";//test
			Server.getFromCustomer('/searchAllRepairDataByCustomerId', {
				openId: app.openId
			}, function (result) {
				app.orderList = result.data;
			});
		});
	},
	methods: {
		getRepairState: function (order,index) {
			// <button class="mui-btn" onclick="app.test()">修改</button>
			switch (order.repairState) {
				case REPAIR_STATE_SUBMIT:
					return {
						state: "status1",
						text: '提交成功，等待审核',
						button: '<button class="mui-btn" onclick="app.cancelRepair('+order.id +','+ order.workOrderNo+',' +index +')">取消报修</button>'
					};
				case REPAIR_STATE_AUDIT:{
					return {
						state: "status2",
						text: '审核通过，等待预约上门',
						button: '<button class="mui-btn confirmBtn" onclick="app.callToServices()">联系我们</button>'
					};
				}
				case REPAIR_STATE_BESPEAK:
					return {
						state: "status3",
						text: '预约成功，等待上门',
						button: '<button class="mui-btn confirmBtn" onclick="app.callToServices()">联系我们</button>'
					};
				case REPAIR_STATE_SIGN:
					return {
						state: "status4",
						text: '服务完成',
						button: '<a href="comment.html?id='+ order.id+'" class="mui-btn confirmBtn" onclick="app.callToServices()">立即评价</a>'
					};
				case REPAIR_STATE_CANCEL:
					return {
						state: "status5",
						text: '服务取消',
						button: ''	
					};
				default:
					return {
						state: "status1",
						text: '提交成功，等待审核',
						button: '<button class="mui-btn" onclick="app.test()">修改</button><button class="mui-btn" onclick="app.cancelRepair('+order.id +','+ order.workOrderNo+')">取消报修</button>'
					};
			}
		},
		callToServices:function(){
			console.log(2341);
			mui.confirm('是否拨打4008889880', function (e) {
				if (e.index != 0) {
					var tel = $('<a href="tel:4008889880"></a>');
					tel[0].click();
				}
			})
		},
		cancelRepair:function(id,workOrderNo,index){
			mui.confirm('是否取消工单['+workOrderNo+']', function(e){
				if(e.index == 1){
					Server.postToCustomer('/cancelRepair', {id: id}, function(result){
						if(result.code === 100){
							mui.toast("取消成功!");
							app.orderList[index].repairState = REPAIR_STATE_CANCEL;
						}else{
							mui.toast('操作失败渲!');
						}
					});
				}
			});
		},
		test:function(){
			mui.toast("test!");
		}
	}
});
//mui初始化
mui.init({
	swipeBack: true //启用右滑关闭功能
});